import React, { useEffect } from 'react'
import { Form, Input as FishInput, Button } from 'antd'
// import { DEFAULT_VALIDATE_MESSAGES } from '../../schema-form/core/constants'

/* eslint-disable */
export const DEFAULT_VALIDATE_MESSAGES = {
  required: "'${label}' 是必填字段222"
  // min: "'${label}'的最小长度为"
}

const rules = [{
  min: 12
}, {
  required: true,
  // message: '自定义的错误'
}, {
  validator: async (_, value) => {
    console.info('value', value, typeof value)
    if (value === '333') {
      return Promise.reject(new Error('至少两名乘客'))
    }
  }
}]

function ListDemo() {
  const [form] = Form.useForm()
  const onFinish = values => {
    console.log('Received values of form: ', values)
  }

  const onChange = () => {
    // form.setFields([{ name: 'test', value: '333', errors: ['发生了错误'] }])
    form.setFields([{ name: 'test', value: '333' }])
    form.setFields([{ name: 'test2', value: '333' }])
    // form.validateFields(['test'])
  }

   const onFieldsChange = (changeFields)=>{
    console.info('fieldChanges',changeFields)
   }

  console.info('rerender')
  return (
    <Form form={form} onFinish={onFinish} onFieldsChange={onFieldsChange} validateMessages={DEFAULT_VALIDATE_MESSAGES}>
      <Form.Item label="输入框" name="test" rules={rules}>
        <FishInput />
      </Form.Item>
      <Form.Item label="输入框" name="test2" rules={rules}>
        <FishInput />
      </Form.Item>
      <Button type="primary" htmlType="submit">Submit</Button>
      <Button type="primary" onClick={onChange} >ChanageValue</Button>
    </Form>
  )
}
export default ListDemo
